package com.mic.service;

import com.mic.dao.UserMapper;
import com.mic.pojo.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class UserServiceImpl implements UserService{
    UserMapper userMapper;
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper=userMapper;
    }

    @Override
    public int addArticle(Article article) {
        return userMapper.addArticle(article);
    }

    @Override
    public int deleteArticle(Integer articleId) {
        return userMapper.deleteArticle(articleId);
    }

    @Override
    public int updateArticle(Article article) {
        return userMapper.updateArticle(article);
    }

    //@Override
   // public List<Article> queryAllArticleByUserId(Integer userId) {
    //    return userMapper.queryAllArticleByUserId(userId);
   // }

    @Override
    public List<Article> queryTopFourArticles() {
        return userMapper.queryTopFourArticles();
    }

    @Override
    public List<Article> queryFiveUserFavoriteArticlesByUserId(Integer userId) {
        return userMapper.queryFiveUserFavoriteArticlesByUserId(userId);
    }

    @Override
    public List<Article> queryAllUserFavoriteArticlesByUserId(Integer userId) {
        return userMapper.queryAllUserFavoriteArticlesByUserId(userId);

    }

    @Override
    public List<Article> queryAllUserArticlesByUserId(Integer userId) {
        return userMapper.queryAllUserArticlesByUserId(userId);
    }

    @Override
    public List<User> queryAllUserSubscriptionById(Integer userId) {
        return userMapper.queryAllUserSubscriptionById(userId);
    }

    @Override
    public List<Article> queryAllArticlesByTime(Integer userId) {
        return userMapper.queryAllArticlesByTime(userId);
    }

    @Override
    public List<User> searchAllRelativeUsersByKeyEqualsUsername(String key) {
        return userMapper.searchAllRelativeUsersByKeyEqualsUsername(key);
    }

    @Override
    public List<Article> searchAllRelativeArticlesByKeyEqualsTitleOrInShort(String key) {
        return userMapper.searchAllRelativeArticlesByKeyEqualsTitleOrInShort(key);
    }

    @Override
    public Article searchArticleByCertainArticleId(Integer certainArticleId) {
        return userMapper.searchArticleByCertainArticleId(certainArticleId);
    }

    @Override
    public User searchUserByCertainUserId(Integer certainUserId) {
        return userMapper.searchUserByCertainUserId(certainUserId);
    }

    @Override
    public Article queryArticleByArticleId(Integer articleId) {
        return userMapper.queryArticleByArticleId(articleId);
    }

    @Override
    public int addComment(Comment comment) {
        return userMapper.addComment(comment);
    }

    @Override
    public List<Comment> queryAllCommentsByArticleId(Integer articleId) {
        return userMapper.queryAllCommentsByArticleId(articleId);
    }


    @Override
    public int deleteComment(Integer commentId) {
        return userMapper.deleteComment(commentId);
    }

    @Override
    public int addSubscription(UserSubscription userSubscription) {
        return userMapper.addSubscription(userSubscription);
    }

    @Override
    public List<UserSubscription> queryAllUserSubscriptionByUserId(Integer userId) {
        return userMapper.queryAllUserSubscriptionByUserId(userId);
    }

    @Override
    public int cancelSubscription(UserSubscription userSubscription) {
        return userMapper.cancelSubscription(userSubscription);
    }


    @Override
    public int addFavorite(UserFavorite userFavorite) {
        return userMapper.addFavorite(userFavorite);
    }

    @Override
    public List<UserFavorite> queryAllUserFavoriteByUserId(Integer userId) {
        return userMapper.queryAllUserFavoriteByUserId(userId);
    }

    @Override
    public int cancelFavorite(UserFavorite userFavorite) {
        return userMapper.cancelFavorite(userFavorite);
    }

    @Override
    public Article hotUser() {
        return userMapper.hotUser();
    }

    @Override
    public List<Article> decsSixArticlesByLikes(Integer userId) {
        return userMapper.decsSixArticlesByLikes(userId);
    }

    @Override
    public int writeAnArticle(Article article) {
        return userMapper.writeAnArticle(article);
    }

    @Override
    public String getInShort(String text) {
        if(text.length()<10){
            return text;
        }
        else {
            String inShort;
            inShort=""+text.charAt(0);
            for (int i=1;i<10;i++){
                inShort+=text.charAt(i);
            }
            inShort+="...";
            return inShort;
        }

    }

    @Override
    public int deleteAnArticle(Integer articleId) {
        return userMapper.deleteAnArticle(articleId);
    }

    @Override
    public int deleteACommentId(Integer commentId) {
        return userMapper.deleteACommentId(commentId);
    }

    @Override
    public Comment getCommentById(Integer commentId) {
        return userMapper.getCommentById(commentId);
    }


    @Override
    public int updatePersonalInfo(User user) {
        return userMapper.updatePersonalInfo(user);
    }

}
